home *** CD-ROM | disk | FTP | other *** search
- /* --------------------------------------------------------------------------
- * Copyright 1992 by Forschungszentrum Informatik (FZI)
- *
- * You can use and distribute this software under the terms of the licence
- * you should have received along with this program.
- * If not or if you want additional information, write to
- * Forschungszentrum Informatik, "STONE", Haid-und-Neu-Strasse 10-14,
- * D-7500 Karlsruhe 1, Germany.
- * --------------------------------------------------------------------------
- */
- /* monitor of persistent storage manager: implementation */
- /* (empty, if MONITOR is not defined) */
-
- #ifdef MONITOR
-
- #include <sys/file.h> // avoid warning for flock
- #include <X11/Xlib.h>
- #include <X11/Intrinsic.h> // TRUE
-
- #include "mon.h"
- #include "psm_err.h" // err_raise, err_SYS
-
- extern "C" {
- int usleep (unsigned);
- }
-
- const uwait=15;
- const NOTICE=500000; // microsec
- const maxwin=10;
-
- const size=9; // size of each box in pixels
- const border=10; // size of border in pixels
-
- const boxes=400; // number of black/white/grey boxes per window
- const dim=20; // dim=sqrt(boxes), number of boxes in each dimension
- const height=dim*(size+1) + 1 + 2*border; // height of window contents in pixels
- const width=dim*(size+1) + 1 + 2*border; // width of window contents in pixels
- const len = dim * (size + 1) + 1;
-
- const char* ERR="from monitor of container manager";
-
- enum Box {black,white,grey};
- enum Border {thick,thin,no};
-
- struct wininfo {
- int cid; // cid=0 if unused
- Window wid; };
- static wininfo wintable[maxwin];
-
- static Display *disp;
- static GC gc;
-
-
- static void paintbox (Window wid, int nbr, Box b) {
- if (nbr < boxes) {
- const ycoord = border + 1 + (nbr / dim) * (size + 1);
- const xcoord = border + 1 + (nbr % dim) * (size + 1);
-
- switch (b) {
- case black: XSetForeground (disp, gc, BlackPixel (disp, 0));
- XSetFillStyle (disp, gc, FillSolid);
- break;
- case white: XSetForeground (disp, gc, WhitePixel (disp, 0));
- XSetFillStyle (disp, gc, FillSolid);
- break;
- case grey: XSetFillStyle (disp, gc, FillTiled); }
- XFillRectangle (disp, wid, gc, xcoord, ycoord, size, size);
- usleep (uwait); } }
-
-
- static void paintborder (Window wid, Border b) {
- switch (b) {
- case thick: XSetForeground (disp, gc, BlackPixel (disp, 0));
- XSetBackground (disp, gc, WhitePixel (disp, 0));
- XSetLineAttributes (disp, gc, 5, LineSolid, CapRound, JoinRound);
- break;
- case thin: paintborder (wid, no);
- XSetForeground (disp, gc, BlackPixel (disp, 0));
- XSetLineAttributes (disp, gc, 2, LineSolid, CapRound, JoinRound);
- break;
- case no: XSetForeground (disp, gc, WhitePixel (disp, 0));
- XSetBackground (disp, gc, BlackPixel (disp, 0));
- XSetLineAttributes (disp, gc, 6, LineSolid, CapRound,JoinRound);}
- XDrawRectangle (disp, wid, gc, border/2, border/2, border+len, border+len);
- usleep(NOTICE); }
-
-
- static void writetitle (Window wid, char* title) {
- if (title != 0) XStoreName (disp, wid, title);
- else XStoreName (disp, wid, ""); }
-
-
- static void paintgrid (Window wid) {
-
- XSetForeground (disp, gc, BlackPixel (disp, 0));
- XSetBackground (disp, gc, WhitePixel (disp, 0));
- XSetFillStyle (disp, gc, FillTiled);
- XFillRectangle (disp, wid, gc, border, border, len, len);
-
- XSetFillStyle (disp, gc, FillSolid);
- XSetLineAttributes (disp, gc, 1, LineSolid, CapRound, JoinRound);
- for (int yoff=0; yoff<len; yoff+=size+1)
- XDrawLine (disp, wid, gc, border, border + yoff,
- border + len - 1, border + yoff);
-
- for (int xoff=0; xoff<len; xoff+=size+1)
- XDrawLine (disp, wid, gc, border + xoff, border,
- border + xoff, border + len - 1); }
-
- static char greybg[] = {0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa};
-
- void mon_initialize () {
-
- disp = XOpenDisplay(0);
- if (disp == 0)
- err_raise(err_SYS, err_MON_SERVER_CONNECTION_FAILED, NULL, FALSE);
- XrmInitialize ();
- gc = XCreateGC (disp, RootWindow (disp, 0), 0, 0);
-
- Pixmap tile = XCreatePixmapFromBitmapData (disp, RootWindow(disp,0), greybg,
- 8, 8, BlackPixel(disp,0), WhitePixel(disp,0), DefaultDepth(disp,0));
- if (tile == 0)
- err_raise(err_SYS, err_MON_PIXMAP_CREATION_FAILED, NULL, FALSE);
- XSetTile (disp, gc, tile);
-
- XSynchronize(disp,TRUE);
- for(int i=0; i<maxwin; i++) wintable[i].cid=0; }
-
-
- mon_Window mon_create (int cid, int last) {
-
- // check if window of cid already displayed and find free slot in wintable
- int n=0; int freepos=maxwin;
- while (n<maxwin && wintable[n].cid!=cid) {
- if(wintable[n].cid==0) freepos=n;
- n++; }
-
- if (n==maxwin) { // monitor of cid not yet displayed
- if (freepos < maxwin) { // window table not exhausted,create new window
- const windx = freepos * 135;
- const windy = 20;
- wininfo& win=wintable[freepos];
- win.cid = cid;
- win.wid = XCreateSimpleWindow(disp, RootWindow (disp, 0),
- windx, windy, width, height, 4,
- BlackPixel (disp, 0), WhitePixel (disp, 0));
- XSetWindowAttributes attr;
- attr.backing_store=Always; // enables automatic repainting
- // also makes waiting for first expose event obsolete !
- XChangeWindowAttributes(disp, win.wid, CWBackingStore, &attr);
- XMapRaised (disp, win.wid); // map window to make it visible
- writetitle (win.wid, 0);
- paintgrid (win.wid);
- for (int nbr=0; nbr<last; nbr++) paintbox (win.wid, nbr, white);
- usleep(NOTICE); } }
- else { // monitor already displayed
- freepos=n; }
-
- return freepos; }
-
-
- void mon_destroy (mon_Window win) {
- if (win < maxwin) {
- XDestroyWindow (disp, wintable[win].wid);
- wintable[win].cid = 0; } }
-
-
- void mon_open(mon_Window win, int rw, char* title) {
- if (win < maxwin) {
- if (rw) paintborder(wintable[win].wid, no);
- else paintborder (wintable[win].wid, thin);
- writetitle (wintable[win].wid, title); } }
-
-
- void mon_close(mon_Window win) {
- if (win < maxwin) paintborder(wintable[win].wid, thick); }
-
-
- void mon_black (mon_Window win, int nbr) {
- if (win < maxwin) paintbox (wintable[win].wid, nbr, black); }
-
-
- void mon_grey (mon_Window win, int nbr) {
- if (win < maxwin) paintbox (wintable[win].wid, nbr, grey); }
-
-
- void mon_white (mon_Window win, int nbr) {
- if (win < maxwin) paintbox (wintable[win].wid, nbr, white); }
-
- #endif MONITOR
-